package top.hmtools.services.adapter;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;

import top.hmtools.beans.DBConnectInfoBean;
import top.hmtools.beans.columnsInfoBeans.ColumnsBaseInfoBean;
import top.hmtools.beans.tableInfoBeans.SQLiteTableInfoBean;
import top.hmtools.beans.tableInfoBeans.TableBaseInfoBean;
import top.hmtools.daos.SQLiteTablesInfoDao;
import top.hmtools.enums.EDBType;

@Component
public class SQLiteDBAdapter extends BaseDBAdapter {

	@Override
	public EDBType getEDBType() {
		return EDBType.Sqlite;
	}

	@Override
	public List<TableBaseInfoBean> getTableInfos(DBConnectInfoBean bean, String dbName) {
		SqlSession sqlSession = this.getSqlSession(bean);
		List<TableBaseInfoBean> result = new ArrayList<>();
		if(sqlSession!=null){
			SQLiteTablesInfoDao mapper = sqlSession.getMapper(SQLiteTablesInfoDao.class	);
			List<SQLiteTableInfoBean> resultTmp = mapper.getAllTablesName(dbName);
			for(SQLiteTableInfoBean tmp:resultTmp){
				result.add((TableBaseInfoBean)tmp);
			}
		}
		return result;
	}

	@Override
	public List<ColumnsBaseInfoBean> getColumnInfos(DBConnectInfoBean bean, String dbName, String tableName) {
		// TODO Auto-generated method stub
		return null;
	}

}
